/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thinkinginjava.svn.reflection.nullobjects;

import java.util.ArrayList;

/**
 *
 * @author public_enemy
 */
public class Staff extends ArrayList<Position> {

    public void add(String title, Person person) {
        add(new Position(title, person));
    }

    public void add(String... titles) {
        for (String title : titles) {
            add(new Position(title));
        }
    }

    public Staff(String... titles) {
        add(titles);
    }

    public boolean positionAvailable(String title) {
        for (Position position : this) {
            if (position.getTitle().equals(title) && position.getPerson() == Person.NULL) {
                return true;
            }
        }
        return false;
    }

    public void fillPosotions(String title, Person hire) {
        for (Position position : this) {
            if (position.getTitle().equals(title) && position.getPerson() == Person.NULL) {
                position.setPerson(hire);
                return;
            }
        }
        throw new RuntimeException("Position " + title + " not available");
    }

    public static void main(String[] args) {
        Staff staff = new Staff("President", "CTO", "Marketing Manager", "Product Manager", "Project Lead", "SoftWare Engineer", "SofrWare Engineer", "SoftWare Engineer", "Testy Engineer", "Technical Writer");
        staff.fillPosotions("President", new Person("Me", "Last", "The Top, Lonely At"));
        staff.fillPosotions("Project Lead", new Person("Janet", "Planner", "The Burbs"));
        if (staff.positionAvailable("SoftWare Engineer")) {
            staff.fillPosotions("SoftWare Engineer", new Person("Bob", "Coder", "Bringht Ligh City"));
        }
        System.out.println(staff);

    }
}
